function aiChoice(round, playerId) {
	let bestScore = [-99, 0], bestChoice = []
	for (const choice of round.players[playerId].choices) {
		const typ = choice[0]
		if (typ === CHOICE_HU || typ === CHOICE_TSUMO) {
			return choice
		}
		if (typ === CHOICE_ADDED_KONG) {
			continue
		}

		let hand = structuredClone(round.players[playerId].hand)
		if (typ) {
			if (typ === CHOICE_DISCARD) {
				removeElementFromArray(hand.tiles, choice[1])
			} else {
				for (const tile of choice[3]) {
					removeElementFromArray(hand.tiles, tile)
				}
				hand.melds.push(structuredClone(choice))
			}
		}

		let counter = newTileCounter()
		countTileArray(counter, hand.tiles)
		for (let i = 0; i < playerCount; ++i) {
			countTileMelds(counter, round.players[i].hand.melds)
			countTileArray(counter, round.players[i].discard)
		}

		const s = shanten(hand)

		function dfs(depth, s) {
			if (!depth) {
				const h = hu(hand)
				return h ? (h.points + 1) : 1
			}
			let ans = 0
			for (let suit = 0; suit < 4; ++suit) {
				for (let tile = (suit === 3 ? 31 : (36 | suit)); tile > 3; tile -= 4)if (counter[tile] > 0) {
					const c = (counter[tile]--)
					hand.tiles.push(tile)

					if (hu(hand) || shantenLessThan(hand, s))
						ans += c * dfs(depth - 1, s - 1)

					removeElementFromArray(hand.tiles, tile)
					++counter[tile]
				}
			}
			return ans
		}
		const score = [-s, dfs((s < aiDepth) ? (s + 1) : aiDepth, s)]
		if (bestScore[0] < score[0] || (bestScore[0] === score[0] && bestScore[1] < score[1])) {
			bestScore = score
			bestChoice = [choice]
		} else if (bestScore[0] === score[0] && bestScore[1] === score[1]) {
			bestChoice.push(choice)
		}
	}
	if (!bestChoice.length) {
		bestChoice = round.players[playerId].choices
	}
	return bestChoice[Math.floor(Math.random() * bestChoice.length)]
}